<?php

if (!defined('access')){
	die ('Direct access Denied!');
} else {
	
	define('libprofil', true);

	class Profil {
		
		private $nom,$prenom,$fix,$port,$profession,$adresse,$cp,$ville;
	
		public function __construct($userid){
			$data = execQuery("SELECT profilnom,profilprenom,profilnumfix,profilnumport,profiladresse,profilcp,profilville,profilprofession,profilpublish
							   FROM profiles WHERE membres_userid = '". $userid ."'")->fetch();
			$this->nom = $data['profilnom'];
			$this->prenom = $data['profilprenom'];
			$this->fix = $data['profilnumfix'];
			$this->port = $data['profilnumport'];
			$this->adresse = $data['profiladresse'];
			$this->cp = $data['profilcp'];
			$this->ville = $data['profilville'];
			$this->profession = $data['profilprofession'];
			$this->publish = $data['profilpublish'];
			$this->userid = $userid;
		}
	
		public function createProfil($nom,$prenom,$fix,$port,$adresse,$cp,$ville,$profession){
			execQuery("INSERT INTO profiles (profilnom,profilprenom,profilnumfix,profilnumport,profiladresse,profilcp,profilville,profilprofession)
				   	   VALUES '".$nom."','".$prenom."','".$fix."','".$port."','".$adresse."','".$cp."','".$ville."','".$profession."'
				   	   WHERE membres_userid = '". $this->userid ."'");
		}
	
		public function updateProfil($nom,$prenom,$fix,$port,$adresse,$cp,$ville,$profession){
			execQuery("UPDATE profiles SET profilnom = '". $nom ."',profilprenom = '". $prenom ."',profilnumfix = '". $fix ."', profilnumport = '". $port ."',
	                   profiladresse = '". $adresse ."', profilcp = '". $cp ."',profilville = '". $ville ."',profilprofession = '". $profession ."' WHERE membres_userid = '". $this->userid ."'");
		}
	
		public function getNom(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->nom;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}
	
		public function getPrenom(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){		
				return $this->prenom;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}
	
		public function getFix(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->fix;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}
	
		public function getPort(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->port;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}
	
		public function getProfession(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->profession;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}

		public function getAdresse(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->adresse;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}

		public function getCP(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->cp;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}

		public function getVille(){
			if (($this->publish == 1) || (isset($_SESSION['userid']) && $this->userid == $_SESSION['userid'])){
				return $this->ville;
			} else {
				return 'Désolé, ce membre ne semble pas vouloir partager ses informations';
			}
		}
	}
}

?>